package com.topisv.tms.web.work.ExceptionOrder;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springside.modules.web.Servlets;

import com.topisv.tms.entity.AreaGroup;
import com.topisv.tms.entity.Customers;
import com.topisv.tms.entity.EdiGoodsSku;
import com.topisv.tms.entity.EdiOrder;
import com.topisv.tms.entity.EdiOrderItem;
import com.topisv.tms.entity.JSONParam;
import com.topisv.tms.entity.LogisticsCompany;
import com.topisv.tms.entity.QueryParamHolder;
import com.topisv.tms.entity.work.WorkOrder;
import com.topisv.tms.entity.work.ExceptionOrder.ExceptionBackItem;
import com.topisv.tms.entity.work.ExceptionOrder.ExceptionOrder;
import com.topisv.tms.repository.work.ExceptionOrder.ExceptionOrderDao;
import com.topisv.tms.service.AreaGroupService;
import com.topisv.tms.service.CustomersService;
import com.topisv.tms.service.EdiGoodsSkuService;
import com.topisv.tms.service.EdiOrderItemService;
import com.topisv.tms.service.EdiOrderService;
import com.topisv.tms.service.LogisticsCompanyService;
import com.topisv.tms.service.account.ShiroDbRealm.ShiroUser;
import com.topisv.tms.service.work.WorkOrderService;
import com.topisv.tms.service.work.ExceptionOrder.ExceptionBackItemService;
import com.topisv.tms.service.work.ExceptionOrder.ExceptionOrderService;
import com.topisv.tms.tools.ExcelStUtil;
import com.topisv.tms.tools.ExcelUtils;
import com.topisv.tms.web.base.BaseDataTableController;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 异常单管理—control
 * @author ch
 *
 */
@Controller
@RequestMapping(value = "/v2/backOrder")
public class BackOrderController extends BaseDataTableController{

	private static final Logger logger = LoggerFactory.getLogger(BackOrderController.class);
	@Autowired
	private WorkOrderService workOrderService;
	@Autowired
	private CustomersService customersService;
	@Autowired
	private EdiOrderService ediOrderService;
	@Autowired
	private ExceptionOrderService exceptionOrderService;
	@Autowired
	private AreaGroupService areaGroupService;
	@Autowired
	private ExceptionBackItemService qcItemService;
	@Autowired
	private EdiOrderItemService ediOrderItemService;
	@Autowired
	private LogisticsCompanyService logisticsCompanyService;
	@Autowired
	private EdiGoodsSkuService ediGoodsSkuService;
	@Autowired
	private ExceptionOrderDao exceptionOrderDao;

	@RequestMapping(value = "show")
	public String show(Model model){
		fillSelectValue(model, null);
		return "work/exceptionOrder/backOrderMgr";
	}
	
	/**
	 * 查询异常单
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "page",method = RequestMethod.POST)
	public void queryBackOrder(@RequestBody JSONParam[] paramJson,HttpServletRequest request,HttpServletResponse response) {
		try {
			
			//查出当前用户关联的商家列表
			ShiroUser curUser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
			// 客户端参数
			QueryParamHolder paramHolder = collectParam(paramJson,"_");
			Map<String, Object> param = paramHolder.getSearchParams();
			String fromDateStr=(String) param.get("fromDate");
			String toDateStr=(String) param.get("toDate");
			String customerCode=(String) param.get("customerCode");
			String warehouseCode=(String) param.get("warehouseCode");
			
			if(StringUtils.isBlank(customerCode)){
				param.put("customerCodes", this.customersService.loadCustomerByAuthority(curUser.jobuuid));
			}else{
				param.put("customerCodes", customerCode);
			}
			
			if(StringUtils.isBlank(warehouseCode)){
				param.put("areagroups", curUser.areagroups);
			}else{
				param.put("areagroups", warehouseCode);
			}
			
			Date fromDate=null;
			Date toDate=null;
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
			if(StringUtils.isNotEmpty(fromDateStr)){
				fromDate=sdf.parse(fromDateStr+" 00:00:00");
			}
			if(StringUtils.isNotEmpty(toDateStr)){
				toDate=sdf.parse(toDateStr+" 23:59:59");
				
			}
			param.put("fromDate1", fromDate);
			param.put("toDate1", toDate);
			
			Page<ExceptionOrder> page = this.exceptionOrderService.loadPageByParam(paramHolder);
			
			// 封装查询结果
			response.getWriter().print(bulidJSON(page));
		} catch (Exception e) {
			
			logger.error("error",e);
		}
	}
	
	/**
	 * 导向登记异常单页面
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "toBackOrderPage/{exceptionType}")
	public String toBackOrderPage(@PathVariable String exceptionType,Model model, ServletRequest request) {
		try {
			
			model.addAttribute("exceptionType",exceptionType);
			
		} catch (Exception e) {
			logger.error("error",e);
		}
		return "work/exceptionOrder/backOrderRegist";
	}
	
	/**
	 * 查询异常单
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxQueryBackOrder")
	public void ajaxQueryBackOrder(ServletRequest request,HttpServletResponse response) {
		
		PrintWriter out=null;
		JSONObject json=null;
		
		try {	
			out = response.getWriter();
			json = new JSONObject();
			String orderno=request.getParameter("orderno"); 
			
			EdiOrder ediOrder=this.ediOrderService.findByOrdernoOrCustomerorderno(orderno);
			if(ediOrder==null){ //不存在此订单
	    		json.put("msg", "noExist");
	    	}else{
	    		WorkOrder workOrder=this.workOrderService.loadByAnyOrderno(orderno);
	    		if(workOrder==null){  //未生成作业批次
	    			json.put("ediOrder", ediOrder);
	    			json.put("msg", "notIn"); 
	    			
	 		    }else{  //已生成作业批次
	 		    	json.put("ediOrder", ediOrder);
	 		    	json.put("workOrder", workOrder);
 			    	String status=workOrder.getStatus();
 					if(! "6".equals(status)){ //没有发货，不能退回
 						json.put("msg", "unSended");  
 					}
	 		    }
	    	}
			out.print(json);
		} catch (Exception e) {
			
			logger.error("error",e);
			json.put("msg", "error");
			out.print(json);
		}
	}
	
	/**
	 * 登记异常单
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxBackOrderRegist")
	public  void ajaxBackOrderRegist(ServletRequest request,HttpServletResponse response) {
		
		PrintWriter out=null;
		JSONObject json=null;
		String msg=null;
		
		try {	
			out = response.getWriter();
			json = new JSONObject();
			ShiroUser curUser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
			String orderno=request.getParameter("orderno");
			String exceptionType=request.getParameter("exceptionType");
			String mark=request.getParameter("mark");
			
			msg=this.exceptionOrderService.regist(orderno,exceptionType,mark,curUser.jobuuid);
		    json.put("msg", msg);
			out.print(json);
			
		} catch (Exception e) {
			
			logger.error("error",e);
			json.put("msg", "error");
			out.print(json);
		}
	}
	
	
	/**
	 * 收货确认
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxReceive")
	public  void ajaxReceive(ServletRequest request,HttpServletResponse response) {
		
		PrintWriter out=null;
		JSONObject json=null;
		String msg=null;
		
		try {	
			out = response.getWriter();
			json = new JSONObject();
			ShiroUser curUser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
			
			Long exceptionOrderId=Long.valueOf(request.getParameter("exceptionOrderId"));
			
			msg=this.exceptionOrderService.receive(exceptionOrderId,curUser.jobuuid);
		    json.put("msg", msg);
			out.print(json);
			
		} catch (Exception e) {
			
			logger.error("error",e);
			json.put("msg", "error");
			out.print(json);
		}
	}
	
	/**
	 * 导向质检页面
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "toQcPage/{exceptionId}")
	public String toQcPage(@PathVariable("exceptionId") Long exceptionId,Model model, ServletRequest request) {
		try {
			
			//异常单
			ExceptionOrder eOrder=this.exceptionOrderService.loadById(exceptionId);
			model.addAttribute("eOrder",eOrder);
			
			//质检明细
			List<ExceptionBackItem> qcItemList=this.qcItemService.loadByExceptionId(exceptionId);
			if(qcItemList.size()>0){
				List<ExceptionBackItem> okList=new ArrayList<ExceptionBackItem>();
				List<ExceptionBackItem> errorList=new ArrayList<ExceptionBackItem>();
				String errorFlag;
				for (ExceptionBackItem qcItem : qcItemList) {
					errorFlag=qcItem.getErrorFlag();
					if("error".equals(errorFlag)){
						errorList.add(qcItem);
					}else if("noterror".equals(errorFlag)){
						okList.add(qcItem);
					}
				}
				model.addAttribute("errorList",errorList);
				model.addAttribute("okList",okList);
			}
			
		} catch (Exception e) {
			
			logger.error("error",e);
		}
		return "work/exceptionOrder/qc";
	}
	
	/**
	 * 质检
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "ajaxQc")
	public void ajaxQc(ServletRequest request,HttpServletResponse response) {

		JSONObject json = null;
		PrintWriter out = null;
		try {
			json = new JSONObject();
			out = response.getWriter();
			
			Long exceptionId=Long.valueOf(request.getParameter("exceptionId"));
			String sku=request.getParameter("sku");
			String batchCode=request.getParameter("batchCode");
			String productDate=request.getParameter("productDate");
			String expireDate=request.getParameter("expireDate");
			String errorFlag=request.getParameter("errorFlag");
			
			//begin add 20160620 lianghe.yuan
			String numStr = request.getParameter("num");
			
			Integer num = null;
			try {
				num = Integer.valueOf(numStr);
			} catch (Exception e) {
				num = 0;
			}
			
			if (num < 0 || num == 0 ) {
				json.put("status","error_num");
				json.put("content", "请输入大于0的正整数!");
				out.print(json.toString());
				
				return;
			}
			//end add 20160620 lianghe.yuan
			//质检点收
			String msg=this.qcItemService.qc(exceptionId,sku,batchCode,productDate,expireDate,errorFlag,num);
			json.put("msg", msg);
			
			//质检明细
			List<ExceptionBackItem> qcItemList=this.qcItemService.loadByExceptionId(exceptionId);
			if(qcItemList.size()>0){
				List<ExceptionBackItem> okList=new ArrayList<ExceptionBackItem>();
				List<ExceptionBackItem> errorList=new ArrayList<ExceptionBackItem>();
				String _errorFlag;
				for (ExceptionBackItem qcItem : qcItemList) {
					_errorFlag=qcItem.getErrorFlag();
					if("error".equals(_errorFlag)){
						errorList.add(qcItem);
					}else if("noterror".equals(_errorFlag)){
						okList.add(qcItem);
					}
				}
				json.put("errorList", errorList);
				json.put("okList", okList);
			}
			
			
		} catch (Exception e) {
			
			json.put("status","error");
			json.put("content",e.getMessage());
			log.error("error",e);
		}
		out.print(json.toString());
	}
	
	/**
	 * 删除质检明细项
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxDeleteQcItem")
	@ResponseBody
	public String ajaxDeleteQcItem(ServletRequest request,HttpServletResponse response) {
		try {	
			Long itemId=Long.valueOf(request.getParameter("itemId")+""); 
			this.qcItemService.deleteQcItem(itemId);
			return "true";
		} catch (Exception e) {
			logger.error("error",e);
			return "false";
		}
	}
	
	/**
	 * 完成质检
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxFinishQc")
	public void ajaxFinishQc(ServletRequest request,HttpServletResponse response) {
		PrintWriter out=null;
		JSONObject json=null;
		try {	
			out = response.getWriter();
			json = new JSONObject();
			Long exceptionId=Long.valueOf(request.getParameter("exceptionId"));
			String msg = exceptionOrderService.finishQc(exceptionId);
			json.put("msg", msg);
		} catch (Exception e) {
			logger.error("error",e);
			json.put("msg", "error");
		}
		out.print(json);
	}
	
	/**
	 * 退回件入库
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxBackin")
	public void ajaxBackin(ServletRequest request,HttpServletResponse response) {
		
		PrintWriter out=null;
		JSONObject json=null;
		String msg=null;
		
		try {	
			out = response.getWriter();
			json = new JSONObject();
			ShiroUser curUser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
			
			Long exceptionOrderId=Long.valueOf(request.getParameter("exceptionOrderId"));
			
			msg=this.exceptionOrderService.backin(exceptionOrderId,curUser.jobuuid);
		    json.put("msg", msg);
			out.print(json);
			
		} catch (Exception e) {
			
			logger.error("error",e);
			json.put("msg", "error");
			out.print(json);
		}
	}
	
	/**
	 * 创建入库单
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxCreateInBill")
	public void ajaxCreateInBill(ServletRequest request,HttpServletResponse response) {
		
		PrintWriter out=null;
		JSONObject json=null;
		String msg=null;
		
		try {	
			out = response.getWriter();
			json = new JSONObject();
			
			ShiroUser curUser = (ShiroUser) SecurityUtils.getSubject().getPrincipal();
			
			String customerCode=request.getParameter("customerCode");
			String warehouseCode=request.getParameter("warehouseCode");
			String exceptionIdArray=request.getParameter("exceptionIdArray");
			JSONArray exceptionIdJsonArray = JSONArray.fromObject(exceptionIdArray);
			
			msg=this.exceptionOrderService.createInBill(customerCode,warehouseCode,exceptionIdJsonArray,curUser.jobuuid);
		    json.put("msg", msg);
			out.print(json);
			
		} catch (Exception e) {
			
			logger.error("error",e);
			json.put("msg", "error");
			out.print(json);
		}
	}

	/**
	 * 导向重发页面
	 * @param model
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "toRecallPage/{exceptionOrderId}")
	public String toBackOrderPage(@PathVariable Long exceptionOrderId,Model model, ServletRequest request) {
		try {
			
			//异常单
			ExceptionOrder exceptionOrder=this.exceptionOrderService.loadById(exceptionOrderId);
			model.addAttribute("exceptionOrder",exceptionOrder);
			
			//原订单
			String orderno=exceptionOrder.getOrderno();
			EdiOrder ediOrder=this.ediOrderService.findByOrdeno(orderno);
			model.addAttribute("ediOrder",ediOrder);
			
			//原订单明细
			List<EdiOrderItem> itemList=this.ediOrderItemService.findByOrdeno(orderno);
			model.addAttribute("itemList",itemList);
			
			//作业信息
			WorkOrder wOrder=this.workOrderService.loadOrderByOrderno(ediOrder.getOrdeno());
			model.addAttribute("wOrder",wOrder);
			
			//快递公司
			List<LogisticsCompany> cmpList=this.logisticsCompanyService.findAll();
			model.addAttribute("cmpList",cmpList);
			
			//商家
			Customers customer=this.customersService.findByCustomerCode(ediOrder.getCustomerCode());
			model.addAttribute("customer",customer);
			
			//作业仓库
			AreaGroup warehouse=this.areaGroupService.findByGroupCode(wOrder.getWarehouseCode());
			model.addAttribute("warehouse",warehouse);
			
			//初始页面
			model.addAttribute("tab1", "active");
			model.addAttribute("tab2", "");
			
		} catch (Exception e) {
			logger.error("error",e);
		}
		return "work/exceptionOrder/recall";
	}
	
	/**
	 * 重发订单
	 * @param request
	 * @param response
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "ajaxRecall")
	public void ajaxRecall(ServletRequest request,HttpServletResponse response) {
		
		PrintWriter out=null;
		JSONObject json=null;
		
		try {
			out = response.getWriter();
			json = new JSONObject();
			
			//获取订单数据
			String companyCode=request.getParameter("cacode");
			String recena=request.getParameter("recena");
			String mobile=request.getParameter("mobile");
			String teleph=request.getParameter("teleph");
			String addres=request.getParameter("addres");
			Long exceptionId=Long.valueOf(request.getParameter("exceptionId"));
			
			//整理商品信息
			String jsonText=request.getParameter("jsonText");
			JSONArray infoArray = JSONArray.fromObject(jsonText);
			Map<String, Integer> infoMap=new HashMap<String, Integer>();
			for (Object info : infoArray) {
				Map<String, Object> map=(Map<String, Object>)info;
				String sku=(String)map.get("sku");
				Integer num=Integer.valueOf(map.get("num")+"");
				infoMap.put(sku, num);
			}
			
			//创建订单
			String msg=this.exceptionOrderService.recall(infoMap,exceptionId,companyCode,recena,mobile,teleph,addres);
			
			json.put("msg", msg);
			out.print(json);
	    		
		} catch (Exception e) {
			logger.error("error.",e);
			json.put("msg", "error");
			out.print(json);
		}
	}
	
	
	/**
	 * 导出取消单
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
//	@RequestMapping(value = "outCancelExcel")
	public void outexportExcel(ServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "_");
		String fromTm = (String)searchParams.get("fromDate");
		String toTm = (String)searchParams.get("toDate");
		Date fromDate=null;
		Date toDate=null;
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if(StringUtils.isNotEmpty(fromTm)){
			fromDate=sdf.parse(fromTm+" 00:00:00");
		}
		if(StringUtils.isNotEmpty(toTm)){
			toDate=sdf.parse(toTm+" 23:59:59");
		}
		String warehouseCode=(String)searchParams.get("warehouseCode");
		String customerCode=(String)searchParams.get("customerCode");
		String allOrderno=(String)searchParams.get("allOrderno");
		String exceptionType=(String)searchParams.get("exceptionType");
		Map<String, Object> param = new HashMap<String, Object>();
		
		
		param.put("exceptionType", exceptionType);
		param.put("customerCodes", customerCode);
		param.put("areagroups", warehouseCode);
		param.put("fromDate1", fromDate);
		param.put("toDate1", toDate);
		param.put("allOrderno", allOrderno);
		List<ExceptionOrder> cancelOrders = exceptionOrderService.findCancelOrder(param);
		log.info("=======开始导出=======");
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-disposition","attachment; filename=" + customerCode +fromTm + toTm+ ".xls");
        DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
		String[] titles = {"类型","商家","仓库","订单编号","客户订单号","来源订单号","运单号","创建人","创建时间","状态","发票号","是否打印保修单"};
		List<Object[]> rs = new ArrayList<Object[]>();
		for(ExceptionOrder co:cancelOrders){
			WorkOrder wo = workOrderService.loadOrderByOrderno(co.getOrderno());
			String status = "";
			status = "1".equals(wo.getStatus())?"创建批次":"2".equals(wo.getStatus())?"创建任务":"3".equals(wo.getStatus())?"已拣货":
					"4".equals(wo.getStatus())?"已灯光拣选":"5".equals(wo.getStatus())?"已包装":"9".equals(wo.getStatus())?"待包装":"";
			String guaranteeStatus = "";
			if("1".equals(wo.getGuaranteeStatus())){
				guaranteeStatus = "是";
			}else{
				guaranteeStatus = "否";
			}
					Object[] object = {
							co.getExceptionType(),
							co.getCustomerCode(),
							co.getWarehouseCode(),
							co.getOrderno(),
							co.getCustomerOrderno(),
							co.getFromOrderno(),
							co.getExpressNo(),
							co.getCreaterUuid(),
							df.format(co.getCreateTime()),
							status,
							wo.getInvoiceNo(),
							guaranteeStatus,
							null
					};
					rs.add(object);
		}
		ExcelUtils.writeExcel(titles,"Sheet1",rs,response.getOutputStream());
        log.info("=======导出结束=======");
	}
	
	/**
     * 导出取消单（重写 2016-06-13 lianghe.yuan）
     * @param request
     * @param response
     */
    @RequestMapping(value = "outCancelExcel")
    public void outexportExcelNew(ServletRequest request, HttpServletResponse response) {
        Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "_");
        String fromDate            = (String)searchParams.get("fromDate");
        String toDate                = (String)searchParams.get("toDate");
        String warehouseCode  = (String)searchParams.get("warehouseCode");
        String customerCode    = (String)searchParams.get("customerCode");
        String allOrderno          = (String)searchParams.get("allOrderno");
        String exceptionType     = (String)searchParams.get("exceptionType");
        
        Map<String, String> param = new HashMap<String, String>();
        param.put("exceptionType", exceptionType);
        param.put("customerCodes", customerCode);
        param.put("areagroups", warehouseCode);
        param.put("fromDate", fromDate);
        param.put("toDate", toDate);
        param.put("allOrderno", allOrderno);
        
        List<Object[]> list = exceptionOrderService.findCancelOrderNew(param);
         //数据为空处理
        if (list == null || list.isEmpty()) {
            try {
                PrintWriter writer = response.getWriter();
                writer.write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\" /></head>"
                        + "<body><script>alert('无符合条件的数据，请检查筛选条件!'); window.history.back();</script></body></html>");
                writer.flush();
                writer.close();
            } catch (Exception ex) {
                logger.error("error. ", ex);
            }
            
            return;
        }
        
        OutputStream os = null;
        
        try {
            response.setContentType("application/octet-stream");
            String fileName = new String((customerCode + fromDate  + toDate  + "_异常单.xls").getBytes("GBK"), "ISO8859-1");
            ((HttpServletResponse)response).setHeader("Content-disposition", "attachment; filename=" + fileName);
            
            String[] titles = {"类型","商家","仓库","订单编号","客户订单号","来源订单号","运单号","创建人","创建时间","状态","发票号","是否打印保修单"
                                ,"快递公司","省","商品重量","发货数量","商品名称"}; //add LiBin 20160914 增加导出信息
            String pageTitle="异常单";
            
            os = response.getOutputStream();
            ExcelStUtil.export(response.getOutputStream(), "异常单", pageTitle, titles, list);
        } catch (Exception ex) {
            logger.error("导出异常单异常，请检查。", ex);
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {}
            }
        }
    }
    
    /**
     * 判断商品是否进行批次号或者效期控制
     * 
     * @param 
     * @return 
     * @throws 
     * @author Administrator
     * @version 1.0.0
     */
    @RequestMapping(value = "checkGoods",method=RequestMethod.POST)
    public void checkGoods(ServletRequest request,HttpServletResponse response) {
        JSONObject json = null;
        PrintWriter out = null;
        try {

            json = new JSONObject();
            out = response.getWriter();
            
            String status = "error";
            String content = null;
            String isBatchMgmt = null;
            String isShelfLifeMgmt = null;
            
            String exceptionId=request.getParameter("exceptionId");
            String sku = request.getParameter("sku");
            
            ExceptionOrder eOrder=this.exceptionOrderDao.findOne(Long.valueOf(exceptionId));
            
            EdiGoodsSku ediGoodsSku = this.ediGoodsSkuService.findByCustomerCodeAndSku(eOrder.getCustomerCode(), sku);
            
            if(ediGoodsSku != null){
                isBatchMgmt = ediGoodsSku.getIsBatchMgmt() == null ? "0" : ediGoodsSku.getIsBatchMgmt();
                isShelfLifeMgmt = ediGoodsSku.getIsShelfLifeMgmt() == null ? "0" : ediGoodsSku.getIsShelfLifeMgmt();
                status = "success";
            }else{
                status = "skuNotExist";
                content = "sku" + sku + "在商家" + eOrder.getCustomerCode() + "下不存在";
            }
            
            json.put("status", status);
            json.put("content", content);
            json.put("isBatchMgmt", isBatchMgmt);
            json.put("isShelfLifeMgmt", isShelfLifeMgmt);
            
         } catch (Exception e) {
            log.error("error",e);
            json.put("status","error");
            json.put("content",e.getMessage());
        }
        out.print(json.toString());
    }
    
}
